//
var Dao = require('./DAO')
var discountDAO = {
  getAllDiscount: function (callback) {
    Dao('SELECT discountID,disimage1,newprice,pastprice,disName FROM discount', null, function (err, results) {
      if (err) {
        callback(err, null)
      } else {
        callback(null, results)
      }
    })
  },
  getDiscountID: function (discountID, callback) {
    Dao('SELECT discountID,disimage1,newprice,discontent,disEname,pastprice,disimage2,disimage3,disimage4,disimage5,disimage6,disimage7,disimage8,disimage9,disimage10,disName FROM discount where discountID=?', [discountID], function (err, results) {
      if (err) {
        callback(err, null)
      } else {
        callback(null, results)
      }
    })
  },
  getclassFind: function ([classID,dis_Name], callback) {
    Dao('SELECT discountID,disimage1,newprice,pastprice,disName FROM discount WHERE  classID=? and (disName LIKE ? or newprice like ? or pastprice like ?) ', [classID,dis_Name,dis_Name,dis_Name], function (err, results) {
      if (err) {
        callback(err, null)
      } else {
        callback(null, results)
      }
    })
  },
  getFind: function (dis_Name, callback) {
    Dao('SELECT discountID,disimage1,newprice,pastprice,disName FROM discount WHERE disName LIKE ? or newprice like ? or pastprice like ? ', [dis_Name,dis_Name,dis_Name], function (err, results) {
      if (err) {
        callback(err, null)
      } else {
        callback(null, results)
      }
    })
  },
  getTime: function (tradeID, callback) {
    Dao('SELECT startTime,endTime FROM trade where status = 1 and tradeID=?', tradeID, function (err, results) {
      if (err) {
        callback(err, null)
      } else {
        callback(null, results)
      }
    })
  },                                                     
  getdisClass: function (classID, callback) {
    Dao(' SELECT discountID,disName,newprice,pastprice,disimage1 FROM `discount` where classID=?', [classID], function (err, results) {
      if (err) {
        callback(err, null)
      } else {
        console.log('测试')
        callback(null, results)
      }
    })
  },                                                     
  upImages: function (discount, callback) {
    
    Dao('UPDATE discount set disimage1=?,disimage2=?,disimage3=?,disimage4=?,disimage5=?,disimage6=?,disimage7=?,disimage8=?,disimage9=?,disimage10=?  where discountID=?', [discount.disimage1,discount.disimage2,discount.disimage3,discount.disimage4,discount.disimage5,discount.disimage6,discount.disimage7,discount.disimage8,discount.disimage9,discount.disimage10,discount.discountID], function (err, results) {
      if (err) {
        callback(err, null)
      } else {
       
        callback(null, results)
      }
    })
  },                                                     
                                            
}

module.exports = discountDAO